import { useMemo, useState } from "react";
import { getStorge } from "./getStorage";

export const useStorage = (name: string, params: any = null) => {
  const [param, setParm] = useState(getStorge(name) ? getStorge(name) : params);

  const storage = useMemo(() => {
    sessionStorage.setItem(name, param);
    return getStorge(name) ? getStorge(name) : param;
  }, [param]);

  return [storage, setParm];
};
